package com.zyh.day05.loadsave

import org.apache.spark.sql.{DataFrame, SaveMode, SparkSession}

import java.util.Properties

object JDBCTest {
  def main(args: Array[String]): Unit = {
    val spark: SparkSession = SparkSession.builder()
      .master("local[*]")
      .appName("pt")
      .getOrCreate()
    import spark.implicits._
    val properties = new Properties()
    properties.put("user", "root")
    properties.put("password", "root")
    val url = "jdbc:mysql://localhost:3306/linux?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai"

    val df: DataFrame = List((1,"zhangsan",20),(2,"lisi",23),(3,"wangwu",23)).toDF("id","name","age")
    //df.write.mode(SaveMode.Overwrite).jdbc(url, "df_user", properties)
    spark.read.jdbc(url,"df_user",properties).show()

    spark.close()
  }
}
